﻿using Furion;
using Furion.DatabaseAccessor;
using Microsoft.Extensions.DependencyInjection;
using MyProject.Data.DbContexts;
using SqlSugar;

namespace MyProject.Data
{
    public class Startup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            // 数据库访问注册
            services.AddDatabaseAccessor(options =>
            {
                // 注册数据库访问上下文
                options.AddDbPool<DefaultDbContext>(DbProvider.SqlServer);
            });

            // 注册 SqlSugar 服务
            services.AddSqlSugar(new ConnectionConfig
            {
                ConnectionString = App.Configuration["ConnectionStrings:DefaultConnectionString"],
                DbType = DbType.SqlServer,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            });
        }
    }
}